package sk.atletis.atletika;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class CompetitionsAdapter extends CursorAdapter
{
	// Constructor
	public CompetitionsAdapter(Context context, Cursor c, int flags) 
	{
		super(context, c, flags);
	}
	
	@Override
	public View newView(Context ctx, Cursor c, ViewGroup root) 
	{
		LayoutInflater inflater = LayoutInflater.from(ctx);
		View view = inflater.inflate(R.layout.articles_list_item, root, false);
		bindView(view, ctx, c);
		return view;
	}
	
	@Override
	public void bindView(View oldView, Context ctx, Cursor c) 
	{
		int nameIndex = c.getColumnIndex(CompetitionsContract.NAME);
		int cityIndex = c.getColumnIndex(CompetitionsContract.CITY);
		int dateIndex = c.getColumnIndex(CompetitionsContract.DATE_FROM);
		
		TextView tvTitle = (TextView) oldView.findViewById(R.id.tvTitle);
		TextView tvPerex = (TextView) oldView.findViewById(R.id.tvPerex);
		TextView tvDate = (TextView) oldView.findViewById(R.id.tvDate);
		
		tvTitle.setText(c.getString(nameIndex));
		tvPerex.setText(c.getString(cityIndex));
		tvDate.setText(DateHelper.DbString2String(c.getString(dateIndex)));
	}
}
